import store from '../store';
import Cookies from 'js-cookie';

const TokenKey = 'vue_app_template_token';

/**
 * 检查当前用户的有没有对应的授权
 */
export function check(authority) {
  const current = [store.getters.userCurrentAuthority];
  return current.some(item => authority.includes(item));
}

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export default {
  check,
  getToken,
  setToken,
  removeToken,
};
